/**
 * 
 */
package com.gosophia.govDoc.action.transientDoc;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.govDoc.dto.TransientDocumentDTO;
import com.gosophia.govDoc.ws.TransientDocumentWebService;
import com.gosophia.springsecurity.UserDetailsImpl;

/**
 * 功能:公文自动保存第一步
 * 
 * @author zhangdongsheng
 * @since 2011-1-30 Copyright (c) 2010 Gosophia corporation All Rights Reserved
 */

@Controller("TransientDocAutoSave")
@Scope("prototype")
@SuppressWarnings("serial")
public class TransientDocAutoSave extends BaseSupportAction {

    private TransientDocumentDTO transientDocumentDto;

    private Long jobId;

    private Long docId;
    @Autowired
    private TransientDocumentWebService transientDocumentWebService;

    private final Logger logger = Logger.getLogger(this.getClass());

    /*
     * @see com.gosophia.commons.web.action.BaseSupportAction#_execute()
     */
    @Override
    public String _execute() throws Exception {

        UserDetailsImpl userDetails = (UserDetailsImpl) SecurityContextHolder
                .getContext().getAuthentication().getPrincipal();
        // 得到当前用户
        Long creatorId = userDetails.getUserAccountDTO().getUserInfoDTO()
                .getUserInfoId();

        if (transientDocumentDto.getCreator() == null) {
            transientDocumentDto.setCreator(creatorId);
        }
        transientDocumentDto.setJobId(jobId);
        logger.debug("输出自动保存信息：" + transientDocumentDto.toString());
        transientDocumentWebService
                .saveOrUpdateTransientDocument(transientDocumentDto);

        return SUCCESS;

    }

    public TransientDocumentDTO getTransientDocumentDto() {
        return transientDocumentDto;
    }

    public void setTransientDocumentDto(
            TransientDocumentDTO transientDocumentDto) {
        this.transientDocumentDto = transientDocumentDto;
    }

    public Long getJobId() {
        return jobId;
    }

    public void setJobId(Long jobId) {
        this.jobId = jobId;
    }

    public Long getDocId() {
        return docId;
    }

    public void setDocId(Long docId) {
        this.docId = docId;
    }

}
